package com.beidouapp.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beidouapp.common.util.UUIDGenerator;
import com.beidouapp.domain.pojo.DrugMsg;
import com.beidouapp.domain.pojo.DrugReference;
import com.beidouapp.domain.pojo.Project;
import com.beidouapp.exception.BusinessException;
import com.beidouapp.manager.DrugsManager;
import com.beidouapp.manager.LeaveMsgManager;
import com.beidouapp.service.DrugsService;

@Service
public class DrugsServiceImpl implements DrugsService {
	@Autowired
	DrugsManager drugsManager;
	@Autowired 
	LeaveMsgManager leaveMsgManager;
   

    @Override
    public List<DrugReference> getDrugReferences(String kw) {
        Map<String, Object> map=new HashMap<>();
        map.put("kw",kw);
        return drugsManager.findDrugsList(map);
    }



    @Override
    public void saveOrgUpdateDrugs(DrugReference drugReference) {
        if(StringUtils.isBlank(drugReference.getId())){
            drugReference.setId(UUIDGenerator.get32UUID());
            drugsManager.insert(drugReference);
        }else{
            drugsManager.update(drugReference);
        }
    }



    @Override
    public DrugReference getDrugDetailById(String id) {
      
        return drugsManager.getDrugDetailById(id);
    }



	@Override
	public void saveLeaveMsg(DrugMsg drugMsg) {
		drugMsg.setId(UUIDGenerator.get32UUID());
		leaveMsgManager.insert(drugMsg);
	}



	@Override
	public List<DrugMsg> getDrugMsgList(DrugMsg d) {
		// TODO Auto-generated method stub
		return leaveMsgManager.getDrugMsgList(d);
	}



	@Override
	public List<DrugReference> findDrugsByMap(Map<String, Object> params,
			Integer offset, Integer limit) {

		List<DrugReference> list=drugsManager.findDrugsByMap(params, offset, limit);
		return  list;
	}



	@Override
	public Integer findDrugsCountByMap(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return drugsManager.findDrugsCountByMap(params);
	}



    @Override
    public void deleteDrugs(String id) {
        if(StringUtils.isBlank(id)){
            throw new BusinessException("请输入合法的ID");
        }
        drugsManager.deleteDrugs(id);
    }
	
	
}